/**
 * Created by digidite on 2017/12/12.
 */

//当前第几个
var currContent = 1;
//当前第几页
var currPage =1;

var navJson = null;

window.onload = function () {
    getProductType();
};

function showProductType(){
    if(navJson.length>0){
        currContent = getCookie("currContent");
        currPage = getCookie("currPage");
        if(currContent=="" || currContent==null || currContent=="null" || currContent==undefined || currContent=="undefined"){
            currContent=1;
            setCookie("currContent",currContent);
        }
        if(currPage=="" || currPage==null || currPage=="null" || currPage==undefined || currPage=="undefined"){
            currPage=1;
            setCookie("currPage",currPage);
        }
        document.getElementById("content").innerHTML = '';
        var show_page = 6;
        if (navJson.length < 6) {
            show_page = navJson.length;
        } else {
            show_page = 6 + parseInt(currPage)-1;
        }
        var num = 0;
        var startIndex = parseInt(currPage)-1;
        for (var i = startIndex; i < show_page; i++) {
            createContents(navJson[startIndex], num + 1);
            startIndex = startIndex + 1;
            num++;
        }
        addBorder(currContent);
    }

}

function createContents(obj,n) {
    if(obj!=null){
        var parNode = document.getElementById("content");
        parNode.innerHTML += '<div class="content-' + n + ' hc" id="content-' + n + '" style="background: url(' + obj.poster + ')"></div>'
    }
}



function addBorder(num){
    if(num>0){
        var obj = document.getElementById("active");
        obj.style.display = 'block';
        obj.style.left = (68 + (220 * (num - 1))) + 'px';
    }

}